

clear 
set scheme lean2, permanent
global pm = char(177)
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user
 
set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"
 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 
 
duplicates drop rnid, force

keep rnid earn_bin1 earn_bin2 earn_bin3 earn_bin4 earn_bin5 earn_bin6 earn_bin7 earn_bin8 earn_bin9 earn_bin10



reshape long earn_bin, i(rnid) j(type) 

collapse (mean) earn_bin (sd) sd=earn_bin (count) n=earn_bin, by(type)



rename earn_bin action

gen standarderror = invttail(n-1,0.025)*(sd / sqrt(n))

gen id2=1 if type==1 
replace id2=2 if type==2  
replace id2=3 if type==3  
replace id2=4 if type==4  
replace id2=5 if type==5   
replace id2=6 if type==6 
replace id2=7 if type==7   
replace id2=8 if type==8   
replace id2=9 if type==9   
replace id2=10 if type==10   

    

 set scheme lean2


generate hiz_avg = action + 1*(standarderror)
generate lowz_avg = action - 1*(standarderror)
 
 
gen zero=0
 
   twoway    (rbar action zero id2)   (rcap hiz_avg lowz_avg id2 ),  legend(off) ///
 ylabel(0(5)30) ///
	xlabel( 1 "Earn. decrease by 12% or more" 2 "Earn. decrease between 8% and 12%" 3 "Earn. decrease between 4% and 8%" 4 "Earn. decrease between 2% and 4%" 5 "Earn. decrease between 0% and 2%" 6 "Earn. increase between 0% and 2%" 7 "Earn. increase between 2% and 4%" 8 "Earn. increase between 4% and 8%" 9 "Earn. increase between 8% and 12%" 10 "Earn. increase by 12% or more", noticks labsize(*0.8) angle(45) ) ///	
	xtitle("Percent chance of different changes in earnings over the next 12 months", size(*1)) ///
	ytitle(" ") ///	  
		name(earn_distribution, replace)	
	   graph display earn_distribution, xsize(20) ysize(10)
		graph export "earn_distribution.eps", replace
		graph export "earn_distribution.pdf", replace
		graph save "earn_distribution.gph", replace



	
	   
	   
	   

